﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../Content/scripts/jquery-1.11.1.min.js"></script>
    <script src="../Content/scripts/bootstrap/bootstrap.min.js"></script>
    <link href="../Content/scripts/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/jquery-ui/jquery-ui.min.js"></script>
    <!-- Bootstrap -->
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />
    <link href="../Content/styles/font-awesome.min.css" rel="stylesheet" />
    <link href="../Content/adminLTE/css/index.css" rel="stylesheet" />
    <link href="../Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
    <link rel="Shortcut icon" href="../images/favicon.ico" />
    <link href="../Content/styles/learun-ui.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/layout/jquery.layout.js"></script>
    <script src="../Content/scripts/plugins/dialog/dialog.js"></script>
    <script src="../Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="../Content/scripts/plugins/jqgrid/jqgrid.min.js"></script>
    <script src="../Content/scripts/plugins/validator/validator.js"></script>
    <script src="../Content/scripts/utils/learun-ui.js"></script>
    <script src="../Content/scripts/utils/learun-form.js"></script>
    <script src="../My97DatePicker/WdatePicker.js"></script>
    <script src="../js/citydata.min.js"></script>
    <script src="../js/cityPicker-2.0.2.js"></script>
    <script src="../js/getUrlParam.js"></script>
    <script src="CustomerJS.js"></script>
    <style>
        html, body {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
    <div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
        <table class="form" id="customeditinfo" style="margin-top:10px;">
            <tr>
                <th class="formTitle">地域<font face="宋体">*</font></th>
                <td class="formValue">
                    <input id="CustomDiYu" type="text" class="form-control" placeholder="请输入地域" isvalid="yes" checkexpession="NotNull" />
                </td>
                <th class="formTitle">厂名<font face="宋体">*</font></th>
                <td class="formValue">
                    <input id="CustomName" type="text" class="form-control" placeholder="请输入厂名" isvalid="yes" checkexpession="NotNull" />
                </td>
                <th class="formTitle">车间<font face="宋体">*</font></th>
                <td class="formValue">
                    <input id="CustomChejian" type="text" class="form-control" placeholder="请输入车间" isvalid="yes" checkexpession="NotNull" />
                </td>
            </tr>


            <tr>
                <th class="formTitle">所在区域<font face="宋体">*</font></th>
                <td class="formValue" colspan="5">
                    <div class="city-picker-select"></div>
                </td>
            </tr>
            <tr>
                <th class="formTitle">详细地址<font face="宋体">*</font></th>
                <td class="formValue" colspan="4">
                    <input id="CustomDetailAddress" type="text" class="form-control" placeholder="请输入详细地址" isvalid="yes" checkexpession="NotNull" />
                </td>

                <td class="formValue">
                    <a id="btn_lat" class="btn btn-default" onclick="onLat(event)" style="height:26px; padding-top:2px"><i class="fa fa-map-marker"></i>&nbsp;自动获取经纬度</a>
                </td>
            </tr>
            <tr>
                <th class="formTitle">经度<font face="宋体">*</font></th>
                <td class="formValue">
                    <input id="CustomLng" type="text" class="form-control" placeholder="请输入地域" isvalid="yes" checkexpession="NotNull" />
                </td>
                <th class="formTitle">纬度<font face="宋体">*</font></th>
                <td class="formValue">
                    <input id="CustomLat" type="text" class="form-control" placeholder="请输入厂名" isvalid="yes" checkexpession="NotNull" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">车间图片</th>
                <td class="formValue">
                    <input type="text" class="form-control" id="CustomImg" readonly />
                    <!--<input type="hidden" id="UploadedFile" value="" />-->

                </td>
                <td class="formValue">

                    <input id="file" type="file" name="file">

                </td>
                <td class="formValue" style="padding-left: 150px;">

                    <a id="btn_upload" class="btn btn-default" onclick="onUpload(event)" style="height:26px; padding-top:2px"><i class="fa fa-upload"></i>&nbsp;上传</a>
                </td>
            </tr>
            <tr>
                <th class="formTitle">安装开始日期<font face="宋体">*</font></th>
                <td class="formValue">
                    <input id="InstallDate" type="text" class="Wdate timeselect" isvalid="yes" checkexpession="NotNull" onclick="WdatePicker()" />
                </td>

            </tr>
            <tr>
                <th class="formTitle">状态<font face="宋体">*</font></th>
                <td class="formValue">
                    <input type="radio" name="optionsRadios" id="optionsRadios1" value="1" checked>在线
                    <input type="radio" name="optionsRadios" id="optionsRadios2" value="0">离线
                </td>
            </tr>

            <tr>
                <th class="formTitle" valign="top" style="padding-top: 4px;">
                    备注
                </th>
                <td class="formValue" colspan="5">
                    <textarea id="Reamrk" class="form-control" style="height: 150px;"></textarea>
                </td>
            </tr>
        </table>
    </div>

    <style>
        .form .formTitle {
            width: 80px;
            font-size: 9pt;
        }

        .timeselect {
            width: 185px;
            height: 30px;
        }

        select {
            border: 1px solid #ccc;
            background: #fff;
            border-radius: 5px;
            color: #333;
            font-size: 9px;
            outline: none;
            width: 180px;
            height: 30px;
            margin-right: 10px;
            box-shadow: 0 0 5px #eee;
        }
    </style>
    <script type="text/javascript">
        var CustomerIDS = UrlParam.paramValues("CustomerID");
        var CustomerID = CustomerIDS[0];
        var provience = "";
        var city = "";
        var area = "";
        var installstate = 0;
        var customerstate = "";

        $(function () {

            //$.customerinfojs.getCustomInfoByID(CustomerID);

            var optionstring = "";
            $.ajax({
                url: "./CustomerHandler.ashx",
                data: {
                    Action: "getCustomInfoByID",
                    ID: CustomerID
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    if (data.length > 0) {
                        console.log(data[0]);
                        $("#CustomDiYu").val(data[0].CustomDiYu);
                        $("#CustomName").val(data[0].CustomName);
                        $("#CustomChejian").val(data[0].CustomChejian);
                        $("#CustomDetailAddress").val(data[0].CustomDetailAddress);
                        $("#CustomLng").val(data[0].CustomLng);
                        $("#CustomLat").val(data[0].CustomLat);
                        $("#CustomImg").val(data[0].CustomImg);
                        $("#InstallDate").val(data[0].InstallDate);
                        $("#Reamrk").val(data[0].Reamrk);
                        if (data[0].CustomeState == 1) {
                            $("#optionsRadios1").checked = true;
                        }
                        else {
                            $("#optionsRadios2").checked = true;
                        }
                        var str = data[0].CustomProvience + ',' + data[0].CustomCity + ',' + data[0].CustomArea;
                        var select = $('.city-picker-select').cityPicker({
                            dataJson: cityData,
                            renderMode: false,
                            autoSelected: true,
                            level: 3,
                            onChoiceEnd: function () {
                                provience = this.values[0].name;
                                city = this.values[1].name;
                                area = this.values[2].name;
                            }
                        })
                        select.setCityVal(str);
                        //select.changeStatus('disabled');
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });

        });

        function onLat(event) {

            var longtitude = 0;
            var latitude = 0;

            //通过百度获取经纬度
            var address = provience + city + area + $("#CustomDetailAddress").val();

            var url = "http://api.map.baidu.com/geocoder/v2/?address=" + address + "&output=json&ak=FG7wxr1VUj0k2NwoO3yXzymd&callback=?";
            $.getJSON(url, function (data) {
                if (data.result) {
                    longtitude = data.result.location.lng;
                    latitude = data.result.location.lat;

                    $("#CustomLng").val(longtitude);
                    $("#CustomLat").val(latitude);
                }
                else {
                    dialogMsg("请输入正确地址", 0);
                }

            });
        }

        function onUpload(event) {
            $.customerinfojs.uploadimage();
        }


        // 保存表单
        function AcceptClick(grid) {
            if (!$('#customeditinfo').Validform()) {
                return false;
            }

            var CustomDiYu = $('#CustomDiYu').val();
            var CustomName = $('#CustomName').val();
            var CustomChejian = $('#CustomChejian').val();
            var CustomDetailAddress = $('#CustomDetailAddress').val();
            var CustomLng = $('#CustomLng').val();
            var CustomLat = $('#CustomLat').val();
            var CustomImg = $('#CustomImg').val();
            var InstallDate = $('#InstallDate').val();
            var Reamrk = $('#Reamrk').val();

            customerstate = $('input:radio:checked').val();

            $.customerinfojs.editCustomInfo(CustomerID, CustomDiYu, CustomName, CustomChejian, provience, city, area, CustomDetailAddress, CustomLng, CustomLat, CustomImg, customerstate, InstallDate, 0, Reamrk, grid);

        }
    </script>
</body>


</html>
